package com.cuanbo.dualscreenteachfu.utils;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.os.Environment;
import android.text.TextUtils;

import com.cuanbo.dualscreenteachfu.R;
import com.cuanbo.dualscreenteachfu.base.App;
import com.cuanbo.dualscreenteachfu.comparator.LogDirComparator;
import com.yanzhenjie.andserver.http.HttpRequest;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 网页工具类
 */
public class HtmlUtil {
    /**
     * 登录验证
     *
     * @param request 请求对象
     */
    public static boolean loginVerify(HttpRequest request) {
        String user = request.getCookieValue("user");
        if (user == null) return false;
        if (user.equals(UserMD5Util.getMD5())) {
            return true;
        }
        return false;
    }

    /**
     * 生成html文件
     *
     * @param htmlName    html文件的名称（自动添加后缀）
     * @param htmlContent html文件的内容
     * @param bl          当为true时如果文件已存在，不会执行该函数
     */
    private static void generateHtml(String htmlName, String htmlContent, boolean bl) {
        File f = new File(App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/html/" + htmlName + ".html");
        if (bl && f.exists() && f.isFile()) {
            return;
        }
        try {
            BufferedWriter writer = new BufferedWriter(
                    new OutputStreamWriter(
                            new FileOutputStream(f), "utf-8"));
            writer.write(htmlContent);
            writer.flush();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 生成index.html
     */
    public static void generateIndex() {
        String resolution = DensityUtil.getScreenWidth(App.getInstance()) + "*" + DensityUtil.getScreenHeigth(App.getInstance());
        String htmlContent = "<!DOCTYPE html>\n" +
                "<html>\n" +
                "<head>\n" +
                "<link rel=\"icon\" href=\"img/logo.png\" type=\"image/x-icon\" />\n" +
                "<link rel=\"shortcut icon\" href=\"img/logo.png\" type=\"image/x-icon\"/>\n" +
                "<meta charset=\"utf-8\">\n" +
                "<title>参数设置</title>\n" +
                "<script type=\"text/javascript\">\n" +
                "function configSave(){\n"+
                "var configForm=document.getElementById(\"configForm\");\n"+
                "configForm.submit();\n"+
                "}\n" +
                "function isValidIP(ip) {\n" +
                "    const parts = ip.split('.');\n" +
                "    if (parts.length !== 4) return false;\n" +
                "    for (const part of parts) {\n" +
                "        if (isNaN(parseInt(part)) || parseInt(part) < 0 || parseInt(part) > 255) return false;\n" +
                "    }\n" +
                "    return true;\n" +
                "}\n" +
                " \n" +
                "function validateIP(event) {\n" +
                "   if(input.value == '')return;\n" +
                "    const input = event.target;\n" +
                "    if (!isValidIP(input.value)) {\n" +
                "        alert('输入的ip格式错误！');\n" +
                "        input.value = '';\n" +
                "    }\n" +
                "}\n"+
                "</script>\n" +
                "<style type=\"text/css\">\n" +
                "input{font-family:微软雅黑;font-size:20px}\n" +
                "body{\n" +
                "\tbackground: url(\"img/bg.jpg\") center;\n" +
                "\tmargin:0px;\n" +
                "}\n" +
                ".divTop{\n" +
                "\tz-index:999;\n" +
                "\tposition:fixed;\n" +
                "\twidth:100%;\n" +
                "\theight:50px;\n" +
                "\tbackground-color:#3872f6;\n" +
                "}\n" +
                ".divBtns{\n" +
                "\ttop: 50px;\n" +
                "\tposition:absolute;\n" +
                "\tmargin-left:10px;\n" +
                "\tmargin-right:10px;\n" +
                "\twidth:1322px;\n" +
                "\theight:50px;\n" +
                "\tmargin:auto;\n" +
                "}\n" +
                ".divBtns2{\n" +
                "\ttop: 100px;\n" +
                "\tposition:absolute;\n" +
                "\tmargin-left:10px;\n" +
                "\tmargin-right:10px;\n" +
                "\twidth:1322px;\n" +
                "\theight:50px;\n" +
                "\tmargin:auto;\n" +
                "}"+
                ".imgLogo{\n" +
                "\tmargin-left:20px;\n" +
                "\twidth:auto;\n" +
                "\theight:50px;\n" +
                "\tdisplay:block;\n" +
                "\tfloat:left;\n" +
                "}\n" +
                ".spanSave{\n" +
                "\tbackground-color:#00000000;\n" +
                "\tborder:0px;\n" +
                "\tline-height:50px;\n" +
                "\tmargin-right:20px;\n" +
                "\tfont-size:20px;\n" +
                "\tcolor:#fff;\n" +
                "\tdisplay:block;\n" +
                "\tfloat:right;\n" +
                "}\n" +
                ".spanCuanBo{\n" +
                "\tline-height:50px;\n" +
                "\tmargin-left:5px;\n" +
                "\tfont-size:22px;\n" +
                "\tcolor:#fff;\n" +
                "\tdisplay:block;\n" +
                "\tfloat:left;\n" +
                "}\n" +
                "a{\n" +
                "\tfont-size:20px;\n" +
                "\tmargin-top:17px;\n" +
                "\tmargin-left:10px;\n" +
                "\tbackground-color:#3872f6;\n" +
                "\tpadding-left:20px;\n" +
                "\tpadding-right:20px;\n" +
                "\tline-height:36px;\n" +
                "\tcolor:#fff;\n" +
                "\tdisplay:block;\n" +
                "\tfloat:left;\n" +
                "\ttext-decoration: none;\n" +
                "\tborder-radius: 7px;\n" +
                "}"+
                ".divConfig{\n" +
                "\ttop:120px;\n" +
                "\tposition:absolute;\n" +
                "\twidth:100%;\n" +
                "\theight:auto;\n" +
                "\tfloat:left;\n" +
                "}\n" +
                "form{\n" +
                "\ttext-align: left;\n" +
                "\tcolor:#fff;\n" +
                "\tfont-size:20px;\n" +
                "}\n" +
                "select{\n" +
                "\tfont-size:16px;\n" +
                "}\n" +
                "option{\n" +
                "\tfont-size:20px;\n" +
                "}\n" +
                "checkbox{\n" +
                "\twidth:100px;\n" +
                "\theight:100px;\n" +
                "}\n" +
                ".inputText{\n" +
                "\twidth:900px;\n" +
                "    border: 1px solid #3872f6;\n" +
                "    border-radius: 3px;\n" +
                "    line-height: 30px;\n" +
                "    padding: 0px 0px 0px 0px;\n" +
                "    background: none;\n" +
                "\tcolor:#fff;\n" +
                "\tfont-size:16px;\n" +
                "}\n" +
                ".sub_btn{\n" +
                "    background: #3872f6;\n" +
                "    color: #fff;\n" +
                "    font-size: 15px;\n" +
                "    width: 420px;\n" +
                "    line-height: 30px;\n" +
                "    border-radius: 3px;\n" +
                "    border: none;\n" +
                "\tmargin:auto;\n" +
                "\tmargin-top:20px;\n" +
                "\tmargin-bottom:20px;\n" +
                "}\n" +
                "textarea{\n" +
                "\twidth:80%;\n" +
                "\tdisplay:block;\n" +
                "\tfloat:left;\n" +
                "}\n"+
                ".txtbatchUpdateCmd{\n" +
                "\tdisplay:block;\n" +
                "\tfloat:left;\n" +
                "}\n" +
                ".inputFile{\n" +
                "\twidth:902px;\n"+
                "}\n" +
                ".inputFrom{\n" +
                "\tmargin: auto;\n" +
                "\twidth:1322px;"+
                "}"+
                ".file_sub_btn{\n" +
                "\tdisplay:block;\n" +
                "\tfloat:right;\n" +
                "\tbackground-color:#3872f6;\n" +
                "\tborder-radius: 7px;\n" +
                "\tborder:0px;\n" +
                "\tpadding-left:20px;\n" +
                "\tpadding-right:20px;\n" +
                "\tline-height:36px;\n" +
                "\tfont-size:18px;\n" +
                "\tcolor:#fff;\n" +
                "}\n" +
                ".mt3{margin-top:3px;}"+
                ".clsConfigForm{\n"+
                "\tmargin:auto;\n" +
                "\twidth:1322px;\n" +
                "}\n"+
                ".titleSpan{\n"+
                "\tfont-size:28px;\n" +
                "\tcolor:#3872f6;\n" +
                "}\n" +
                ".tdLeft{\n"+
                "\twidth:260px;\n"+
                "\ttext-align:right;\n" +
                "}\n" +
                "input::placeholder{\n" +
                "\tcolor:#bbb;\n" +
                "}\n" +
                "</style>\n" +
                "</head>\n" +
                "<body>\n" +
                "\t<div class=\"divTop\">\n" +
                "\t\t<img class=\"imgLogo\" src=\"img/h_cuanbo.png\"><span class=\"spanCuanBo\"></span><button class=\"spanSave\" onclick=\"configSave()\">保存</button>\n" +
                "\t</div>\n" +
                "\t<div class=\"divBtns\">\n" +
                "\t\t<a href=\"/clearLog\">清空日志</a>" +
                "\t\t<a href=\"/log\">下载日志</a>" +
                "\t\t<a href=\"/classRoomDownload\">导出教室</a>" +
                "\t\t<a href=\"/systemRestart\">系统重启</a>" +
                "\t</div>\n" +
                "\t<div class=\"divConfig\">\n" +
                "\t<form class=\"inputFrom\" action=\"upload\" method=\"post\" enctype=\"multipart/form-data\">\n" +
                "\t<table>\n"+
                "\t\t<td class=\"tdLeft\">导入教室：</td><td><input  class=\"inputFile mt3\" type=\"file\" name=\"appconfig\" multiple>&nbsp&nbsp<input type=\"submit\" class=\"file_sub_btn\" value=\"确定\"></td></tr>\n" +
                "\t</table>\n"+
                "\t</form>\n" +
                "\t<form class=\"inputFrom\" action=\"inputApk\" method=\"post\" enctype=\"multipart/form-data\">\n" +
                "\t<table>\n"+
                "\t\t<tr><td class=\"tdLeft\">软件更新：</td><td><input  class=\"inputFile mt3\" type=\"file\" name=\"apkFile\" multiple>&nbsp&nbsp<input type=\"submit\" class=\"file_sub_btn\" value=\"确定\"></td></tr>\n" +
                "\t</table>\n"+
                "\t</form>\n" +
                "<form class=\"clsConfigForm\" id=\"configForm\" action=\"set\" method=\"post\">\n" +
                //"\t\t<input class=\"sub_btn\" type=\"submit\" value=\"保存\"><br>\n" +
                "<table>\n"+
                "\t\t<tr><td class=\"tdLeft\"><span class=\"titleSpan\">教室&nbsp&nbsp</span></td><td></td>\n" +
                "\t\t<tr><td class=\"tdLeft\">名称：</td><td><input class=\"inputText\" type=\"text\" name=\"className\" placeholder=\"请在这里输入教室名称\" value=\"" + StringUtil.checkEmpty(App.configInfo.getClassName()) + "\"></td></tr>\n" +
                "\t\t<tr><td class=\"tdLeft\">教室编号：</td><td><input class=\"inputText\" type=\"text\" name=\"classId\" value=\"" + StringUtil.checkEmpty(App.configInfo.getClassId()) + "\"></td></tr>\n" +
                "\t\t<tr><td class=\"tdLeft\"><span class=\"titleSpan\">本机&nbsp&nbsp</span></td><td></td>\n" +
                "\t\t<tr><td class=\"tdLeft\">安卓版本：</td><td>" + AndroidVersionUtil.get() + "</td></tr>\n" +
                "\t\t<tr><td class=\"tdLeft\">软件版本：</td><td>" + VersionUtil.getName() + "</td></tr>\n" +
                "\t\t<tr><td class=\"tdLeft\">屏幕分辨率：</td><td>" + resolution + "</td></tr>\n" +
                "\t\t<tr><td class=\"tdLeft\"><span class=\"titleSpan\">日志&nbsp&nbsp</span></td><td></td>\n" +
                "\t\t<tr><td class=\"tdLeft\">存储率：</td><td>" + LogUtil.getUseRate() + "%</td></tr>\n" +
                "\t\t<tr><td class=\"tdLeft\"><span class=\"titleSpan\">中控&nbsp&nbsp</span></td><td></td>\n" +
                "\t\t<tr><td class=\"tdLeft\">IP地址：</td><td><input class=\"inputText\" type=\"text\" name=\"matrix\" onblur=\"validateIP(event)\" onkeyup=\"value=value.replace(/[^\\d.]/g,'')\" placeholder=\"请在这里输入中控ip\" value=\"" + StringUtil.checkEmpty(App.configInfo.getMatrixIP()) + "\"></td></tr>\n" +
                "\t\t<tr><td class=\"tdLeft\">端口号：</td><td><input class=\"inputText\" type=\"text\" name=\"matrixPort\" onblur=\"validateIP(event)\" onkeyup=\"value=value.replace(/[^\\d]/g,'')\" placeholder=\"请在这里输入端口号\" value=\"" + App.configInfo.getMatrixPort() + "\"></td></tr>\n" +

                "</table>\n"+
                "\t</form>\n" +
                "\t</div>\n" +
                "</body>\n" +
                "</html>";
        generateHtml("index", htmlContent, false);
    }

    /**
     * 生成login.html
     */
    public static void generateLogin(HttpRequest request) {
        String strLoginResult=null;
        int loginResult=0;
        if(request!=null){
            strLoginResult=request.getParameter("loginResult");
        }
        if(!TextUtils.isEmpty(strLoginResult)){
            loginResult= Integer.valueOf(strLoginResult);
        }
        String strLoginMsg="";
        if(loginResult==-1){
            strLoginMsg="密码错误,登录失败!";
        }
        String htmlContent = "<!DOCTYPE html>\n" +
                "<html>\n" +
                "<head>\n" +
                "<link rel=\"icon\" href=\"img/logo.png\" type=\"image/x-icon\" />\n" +
                "<link rel=\"shortcut icon\" href=\"img/logo.png\" type=\"image/x-icon\"/>\n" +
                "<meta charset=\"utf-8\">\n" +
                "<title>登录</title>\n" +
                "<style type=\"text/css\">\n" +
                "input{font-family:微软雅黑;font-size:26px}\n" +
                "body{\n" +
                "\tbackground: url(\"img/loginbg.jpg\") center;\n" +
                "\tbackground-size:over;\n" +
                "\twidth:100%;\n" +
                "\theight:100%;\n" +
                "\tmargin:0px;\n" +
                "}" +
                ".divLogin{\n" +
                "\tbackground: url(img/main_bg.png) repeat;\n" +
                "\tborder-radius: 8px;\n" +
                "\ttop: 0;\n" +
                "    right: 0;\n" +
                "    bottom: 0;\n" +
                "    left: 0;\n" +
                "\tpadding-right: 15px;\n" +
                "    padding-left: 15px;\n" +
                "\tbox-sizing: border-box;\n" +
                "\twidth:300px;\n" +
                "\theight:210px;\n" +
                "\tposition:absolute;\n" +
                "\tmargin:auto;\n" +
                "\tdisplay:block\n" +
                "}\n" +
                "h2{\n" +
                "\tpadding-top: 120px;\n" +
                "\ttext-align: center;\n" +
                "\tfont-family: inherit;\n" +
                "    font-weight: 500;\n" +
                "    line-height: 1.1;\n" +
                "\tcolor: #fff;\n" +
                "\tfont-size:30px;\n" +
                "}\n" +
                "h4{\n" +
                "\ttext-align: center;\n" +
                "\tfont-family: inherit;\n" +
                "    font-weight: 500;\n" +
                "    line-height: 1.1;\n" +
                "\tcolor: #fff;\n" +
                "\tmargin-bottom:0px;\n" +
                "\tfont-size:20px;\n" +
                "}\n" +
                "form{\n" +
                "\ttext-align: center;\n" +
                "}\n" +
                ".login_input{\n" +
                "\twidth:210px;\n" +
                "\tmargin-top: 20px;\n" +
                "    border: 1px solid #3872f6;\n" +
                "    border-radius: 3px;\n" +
                "    line-height: 40px;\n" +
                "    padding: 0px 0px 0px 10px;\n" +
                "    background: none;\n" +
                "\tcolor:#fff;\n" +
                "\tfont-size:12px;\n" +
                "}\n" +
                ".spanLoginResult{\n"+
                "\ttext-align: center;\n" +
                "\tfont-family: inherit;\n" +
                "\tfont-weight: 500;\n" +
                "\tline-height: 1.1;\n" +
                "\tcolor: #ff5b5b;\n" +
                "\tmargin-bottom: 0px;\n" +
                "\tfont-size: 14px;\n"+
                "\tmargin-top: 10px;"+
                "}\n"+
                ".login_btn{\n" +
                "\tdisplay: block;\n" +
                "    background: #3872f6;\n" +
                "    color: #fff;\n" +
                "    font-size: 15px;\n" +
                "    width: 220px;\n" +
                "    line-height: 40px;\n" +
                "    border-radius: 3px;\n" +
                "    border: none;\n" +
                "\tmargin:auto;\n" +
                "\tmargin-top:20px\n" +
                "}\n" +
                ".divTop{\n" +
                "\twidth:100%;\n" +
                "\theight:50px;\n" +
                "\tbackground-color:#3872f6;\n" +
                "}\n" +
                ".spanCuanBo{\n" +
                "\tline-height:50px;\n" +
                "\tmargin-left:5px;\n" +
                "\tfont-size:24px;\n" +
                "\tcolor:#fff;\n" +
                "\tdisplay:block;\n" +
                "\tfloat:left;\n" +
                "}\n" +
                ".imgLogo{\n" +
                "\tmargin-left:20px;\n" +
                "\twidth:auto;\n" +
                "\theight:50px;\n" +
                "\tdisplay:block;\n" +
                "\tfloat:left;\n" +
                "}\n" +
                "\t.divBotton{\n"+
                "\tposition:fixed;\n" +
                "\tbottom:0;\n" +
                "\twidth:100%;\n" +
                "\theight:80px;\n" +
                "\tbackground-color:#16223c;\n" +
                "\tborder-top:1px solid #fff;\n"+
                "\t}\n"+
                "\t.divCorporation{\n"+
                "\tcolor:#ffffff;\n"+
                "\twidth:372px;\n"+
                "\tmargin:auto;\n"+
                "\tline-height:80px;\n"+
                "\tfont-size:12px;\n"+
                "\t}\n"+
                "</style>\n" +
                "</head>\n" +
                "<body>\n" +
                "\t<div class=\"divTop\">\n" +
                "\t\t<img class=\"imgLogo\" src=\"img/h_cuanbo.png\"></img><span class=\"spanCuanBo\"></span>\n" +
                "\t</div>\n" +
                "\t<div class=\"divLogin\">\n" +
                "\t\t<h4>用户登录</h4>\n" +
                "\t\t<form action=\"login\" method=\"post\">\n" +
                "\t\t\t<input class=\"login_input\" type=\"password\" name=\"password\" placeholder=\"请输入密码\"><br>\n" +
                "\t\t\t<input class=\"login_btn\" type=\"submit\" value=\"登录\">\n" +
                "\t\t</form>\n" +
                "\t\t<h4 class=\"spanLoginResult\">"+strLoginMsg+"</h4>\n" +
                "\t</div>\n" +
                "<body>\n" +
                "\t<div class=\"divBotton\">\n" +
                "\t\t<div class=\"divCorporation\">Copyright 深圳市载航智能科技有限公司 by 设备控制v"+VersionUtil.getName()+"</div>\n" +
                "\t</div>\n" +
                "</body>\n" +
                "</html>";
        generateHtml("login", htmlContent, false);
    }

    /**
     * 生成根目录
     */
    public static void generateRootDir() {
        new File(App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/html").mkdirs();
        new File(App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/html/img").mkdirs();
        new File(App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/log").mkdirs();
        new File(App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/apk").mkdirs();
        new File(App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/capture").mkdirs();
        new File(App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/classRoomInfo").mkdirs();
        new File(App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/html/js").mkdirs();
    }

    /**
     * 生成log.html
     */
    public static void generateLog() {
        String dir = App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/log";
        File fDir = new File(dir);
        String htmlLogFiles = "";
        List<File> dirList = new ArrayList<>();
        if (fDir != null && fDir.exists() && fDir.isDirectory()) {
            File[] files = fDir.listFiles();
            for (File f : files) {
                if (f.isDirectory()) {
                    dirList.add(f);
                }
            }
        }
        if (dirList.size() > 1) {
            Collections.sort(dirList, new LogDirComparator());
        }
        for (int i = 0; i < dirList.size(); i++) {
            File f = dirList.get(i);
            htmlLogFiles += "\t\t<a href=\"/" + f.getName() + "\">" + f.getName() + "</a><br>";
        }
        String htmlContent = "<!DOCTYPE html>\n" +
                "<html>\n" +
                "<head>\n" +
                "<link rel=\"icon\" href=\"img/logo.png\" type=\"image/x-icon\" />\n" +
                "<link rel=\"shortcut icon\" href=\"img/logo.png\" type=\"image/x-icon\"/>\n" +
                "<meta charset=\"utf-8\">\n" +
                "<title>日志</title>\n" +
                "<style type=\"text/css\">\n" +
                "input{font-family:微软雅黑;font-size:26px}\n" +
                "body{\n" +
                "\tbackground: url(\"img/bg.jpg\") center;\n" +
                "\twidth:100%;\n" +
                "\theight:100%;\n" +
                "}div{\n" +
                "\twidth:100%;\n" +
                "\theight:auto;\n" +
                "}\n" +
                "a{\n" +
                "\tcolor:#0f0;\n" +
                "\tfont-size:28px;\n" +
                "}\n" +
                "form{\n" +
                "\ttext-align: left;\n" +
                "\tcolor:#fff;\n" +
                "\tfont-size:28px;\n" +
                "}\n" +
                "select{\n" +
                "\tfont-size:24px;\n" +
                "}\n" +
                "option{\n" +
                "\tfont-size:28px;\n" +
                "}\n" +
                "checkbox{\n" +
                "\twidth:100px;\n" +
                "\theight:100px;\n" +
                "}\n" +
                ".inputText{\n" +
                "\twidth:500px;\n" +
                "\tmargin-left: 10px;\n" +
                "    border: 1px solid #3872f6;\n" +
                "    border-radius: 3px;\n" +
                "    line-height: 30px;\n" +
                "    padding: 0px 0px 0px 0px;\n" +
                "    background: none;\n" +
                "\tcolor:#fff;\n" +
                "\tfont-size:16px;\n" +
                "}\n" +
                ".sub_btn{\n" +
                "    background: #3872f6;\n" +
                "    color: #fff;\n" +
                "    font-size: 15px;\n" +
                "    width: 420px;\n" +
                "    line-height: 30px;\n" +
                "    border-radius: 3px;\n" +
                "    border: none;\n" +
                "\tmargin:auto;\n" +
                "\tmargin-top:20px;\n" +
                "\tmargin-bottom:20px;\n" +
                "}\n" +
                ".file_sub_btn{\n" +
                "    background: #3872f6;\n" +
                "    color: #fff;\n" +
                "    font-size: 22px;\n" +
                "    width: 80px;\n" +
                "    line-height: 35px;\n" +
                "    border-radius: 3px;\n" +
                "    border: none;\n" +
                "    margin:auto;\n" +
                "}\n" +
                "</style>\n" +
                "</head>\n" +
                "<body>\n" +
                "\t<div>\n" +
                htmlLogFiles +
                "\t</div>\n" +
                "</body>\n" +
                "</html>";
        generateHtml("log", htmlContent, false);
    }

    /**
     * 生成Html图片资源
     *
     * @param res 资源
     */
    public static void generateImgs(Resources res) {
        BitmapUtil.savePng(App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/html/img/logo.png", res, R.drawable.logo);
        BitmapUtil.saveJPG(App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/html/img/bg.jpg", res, R.drawable.bg);
        BitmapUtil.saveJPG(App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/html/img/loginbg.jpg", res, R.drawable.bg);
        BitmapUtil.savePng(App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/html/img/main_bg.png", res, R.drawable.h_main_bg);
        BitmapUtil.savePng(App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/html/img/h_cuanbo.png", res, R.drawable.h_cuanbo);
    }

    public static void generateFiles(Context context) {
        try{
            AssetManager assetManager = context.getAssets();
            InputStream is =assetManager.open("jquery.min.js");
            FileUtil.copy(is,App.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/html/js/jquery.min.js");
        }catch (Exception e){
            LogUtil.addError("==================生成Html文件失败===================");
            LogUtil.addError(e);
            LogUtil.addError("=====================================");
        }
    }

}
